<template>
  <div class="login" v-loading="loading">
    <el-card class="box-card login_form">
      <div slot="header" class="clearfix">
        <h2>玉树市CIM智慧校园平台</h2>
      </div>
      <el-form ref="form" :model="loginForm" label-width="80px">
        <el-form-item label="账号">
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="loginForm.password"></el-input>
        </el-form-item>
      </el-form>
      <el-button @click="login" class="login_btn" type="primary"
        >登陆</el-button
      >
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "admin",
      loading: false,
      loginForm: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      this.loading = true;
      this.$store
        .dispatch("user/login", { username: this.loginForm.username })
        .then(() => {
          this.loading = false;
          this.$router.push({
            path: this.$route.query.redirect || "/",
          });
        })
        .catch((error) => alert(error));
    },
  },
};
</script>

<style lang = "scss" scoped>
.login {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url("../assets/img/login_background.jpeg");
  .login_form {
    width: 40%;
    height: 50%;
    .login_btn {
      width: 80%;
      margin: 5% 10%;
    }
  }
}
</style>